package com.zy.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.zy.dao.GetMarksDao;
import com.zy.entity.Mark; // 假设有一个Mark实体类
import com.zy.utils.JdbcUtil;


public class GetMarksDaoImpl implements GetMarksDao {
    @Override
    public List<Mark> getMarks(int offset, int limit) {
        List<Mark> marks = new ArrayList<>();
        String sql = "SELECT * FROM tb_marks LIMIT ? OFFSET ?";
        try (Connection conn = JdbcUtil.getConnection();
             PreparedStatement pstmt = conn.prepareStatement(sql)) {
            pstmt.setInt(1, limit);
            pstmt.setInt(2, offset);
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                Mark mark = new Mark();
                mark.setId(rs.getInt("id"));
                mark.setContent(rs.getString("content"));
                mark.setUserId(rs.getInt("user_id"));
                marks.add(mark);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return marks;
    }



}

